package com.zb.select.controller;

import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjUserContactService;
import com.zb.service.ZjUserLevelService;
import com.zb.service.ZjUserService;
import com.zb.service.ZjUserTypeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.UserSelectSearch;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author WEN
 * @Date 2023/8/14 0014
 **/
@Api(tags = "用户下拉类接口")
@RestController
@RequestMapping("/select/user")
public class UserSelectController {
    @Resource
    private ZjUserService userService;
    @Resource
    private ZjUserContactService userContactService;
    @Resource
    private ZjUserLevelService userLevelService;
    @Resource
    private ZjUserTypeService userTypeService;

    @ApiOperation("分页获取用户下拉数据列表")
    @PostMapping("/pageSelect")
    public Result pageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("分页获取用户下拉数据成功").data(userService.pageSelect(custAccId, selectVo));
    }

    @ApiOperation("获取报单客户下拉数据列表")
    @PostMapping("/getOrderUserSelect")
    public Result getOrderUserSelect(HttpServletRequest request, @RequestBody UserSelectSearch search) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取报单客户下拉数据列表成功").data(userService.getOrderUserSelect(custAccId, search));
    }

    @ApiOperation("分页获取客户下拉数据，带出所有联系人及对应的账号")
    @PostMapping("/pageUserSelect")
    public Result pageUserSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success().data(userContactService.pageUserSelect(custAccId, selectVo));
    }

    @ApiOperation("分页获取用户联系人下拉数据列表")
    @PostMapping("/{userId}")
    public Result pageContactSelect(@PathVariable @ApiParam(value = "用户ID", required = true) Long userId, @RequestBody SelectVo selectVo) {
        return Result.success("获取用户联系人下拉数据成功").data(userContactService.pageContactSelect(userId, selectVo));
    }

    @ApiOperation("分页获取用户级别下拉数据列表")
    @PostMapping("/levelPageSelect")
    public Result levelPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("分页获取用户级别下拉数据成功").data(userLevelService.pageSelect(custAccId, selectVo));
    }

    @ApiOperation("分页获取用户分类下拉数据列表")
    @PostMapping("/typePageSelect")
    public Result typePageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("分页获取用户分类下拉数据成功").data(userTypeService.pageSelect(custAccId, selectVo));
    }

    @ApiOperation("获取出入库客户下拉数据列表")
    @PostMapping("/getStoreUserPageSelect")
    public Result getStoreUserPageSelect(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取出入库客户下拉数据列表成功").data(userService.getStoreUserPageSelect(custAccId, selectVo));
    }
}
